home *** CD-ROM | disk | FTP | other *** search
- /* docscan.c - scan indexed documents */
- #include "stdio.h"
- #include "ctype.h"
- #include "cminor.h"
- #include "document.h"
- #include "btree.h"
- #include "bt_macro.h"
-
- int compf() ;
- int sizef() ;
- #define RW_MODE 2 /* read & write allowed */
- #define BOF_REL 0 /* seek relative to Begin.-of-file */
-
- main(argc,argv)
- int argc ;
- char *argv[] ;
- {
- int ret , datfile , line ;
- char fn[65] ;
- RECPOS fs ;
- IX_DESC ixd ;
- DOCUMENT doc ;
- ENTRY e, e2 ;
-
- if( argc < 2 )
- { printf(" USAGE: docindex doc-file-name \n") ;
- exit(5) ;
- }
-
- add_str(fn,argv[1],".idx") ;
- if( openix(fn,&ixd,compf,sizef) < 0 )
- { printf(" can't open the index file \n") ;
- exit(11) ;
- }
-
- add_str(fn,argv[1],".dat") ;
- datfile = gopen(fn,RW_MODE,BIN_MODE) ;
- if( datfile < 0 )
- { printf(" can't open the data file \n") ;
- closeix(&ixd) ;
- exit(12) ;
- }
-
- scan_input(e.key) ;
- ret = find_ix(&e,&ixd) ;
- get_current(&e2,&ixd) ; /* find out where we are */
- line = 0 ;
- while( cmp_part(e.key,e2.key) == 0 )
- { lseek(datfile,e2.rptr,BOF_REL) ; /* retrieve the data */
- read(datfile,&doc,sizeof(DOCUMENT) ) ;
- if( line >= 20 )
- { printf("\n press a key for more \n") ;
- getkey() ;
- line = 0 ;
- }
- display_doc(&doc) ;
- line = line + 5 ;
- if( get_next(&e2,&ixd) == EOIX )
- break ;
- }
- closeix(&ixd) ;
- }
-
-
- int scan_input(s)
- char s[] ;
- {
- char ans[81] ;
-
- printf(" which field to scan ? \n") ;
- printf(" a = Addressee / d = Date / s = Subject :") ;
- getstr(ans,80) ;
- s[0] = toupper(ans[0]) ;
- s[1] = '*' ;
- s[2] = '\0' ;
-
- printf(" value to look for: ") ;
- getstr(ans,ADR_LEN-1) ;
- strcat(s,ans) ;
- }
-
- int display_doc(pdoc) /* display one document record */
- DOCUMENT *pdoc ;
- {
- printf("\n document file name: %s \n",pdoc->dname) ;
- printf(" addressed to: %s \n",pdoc->addressee) ;
- printf(" date sent: %s \n",pdoc->date) ;
- printf(" subject: %s \n",pdoc->subject) ;
- }
-
-
-
-